import java.awt.BorderLayout;
import java.awt.Component;
 
import javax.swing.AbstractListModel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
 
public class RowHeaderTable extends JFrame {
   public RowHeaderTable(){
      super("Row Header Table");
 
      ListModel lm = new RowHeaderListModel();
 
      DefaultTableModel dtm = new DefaultTableModel(lm.getSize(), 4);
      JTable table = new JTable(dtm);
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
      JList rowHeader = new JList(lm);
      rowHeader.setFixedCellWidth(60);
      rowHeader.setFixedCellHeight(table.getRowHeight());
      rowHeader.setCellRenderer(new RowHeaderRenderer(table));
 
      JScrollPane scroll = new JScrollPane(table);
      scroll.setRowHeaderView(rowHeader);
      getContentPane().add(scroll, BorderLayout.CENTER);
   }
 
   public static void main(String[] args){
      RowHeaderTable frame = new RowHeaderTable();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }
}
 
class RowHeaderListModel extends AbstractListModel{
   String strRowHeaders[] = {"Woche 1", "Woche 2", "Woche 3", "Woche 4", "Woche 5", "Woche 6", "Woche 7"};
 
   public int getSize(){
      return strRowHeaders.length;
   }
 
   public Object getElementAt(int index){
      return strRowHeaders[index];
   }
}
 
class RowHeaderRenderer extends JLabel implements ListCellRenderer{
   RowHeaderRenderer(JTable table){
      JTableHeader tableHeader = table.getTableHeader();
      setBorder(UIManager.getBorder("TableHeader.cellBorder"));
      setHorizontalAlignment(CENTER);
      setForeground(tableHeader.getForeground());
      setOpaque(true);  // Damit der Hintergrund nicht verändert wird
      setFont(tableHeader.getFont());
   }
 
   public Component getListCellRendererComponent(JList list, Object value, int index, 
                                                 boolean fSelected, boolean fCellHasFocus){
      setText((value == null) ? "" : value.toString());
      return this;
   }
}